//
//  WmcBaseCollectionCell.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/3/14.
//

import UIKit

class WmcBaseCollectionCell: UICollectionViewCell {
    // Lifecycle

    override init(frame: CGRect) {
        super.init(frame: frame)
        config()
        makeUI()
    }

    @available(*, unavailable)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    deinit {
        WmcLogManager.DebugLog(type: .delloc, log: "CollectionCell被释放\(self)")
    }

    // Internal

    override class var layerClass: AnyClass {
        return CAShapeLayer.self
    }

    /// 箭头
    lazy var arrowImageView: UIImageView = {
        let imageView = UIImageView(image: "arrow_right".wmc_image)
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()

    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = .wmc_lineColor
        return view
    }()

    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.adjustsFontSizeToFitWidth = true
        return label
    }()

    lazy var imageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()

    /// 视图的layer
    var shapeLayer: CAShapeLayer {
        guard let layer = layer as? CAShapeLayer else { return CAShapeLayer() }
        return layer
    }

    override func addSubview(_ view: UIView) {
        if view == contentView {
            super.addSubview(view)
        } else {
            contentView.addSubview(view)
        }
    }

    func config() {
        // Xcode和iOS14需要设置这个
        if #available(iOS 14.0, *) {
            self.backgroundConfiguration = .clear()
        }
        shapeLayer.fillColor = UIColor.clear.cgColor
        shapeLayer.strokeColor = UIColor.wmc_lineColor.cgColor
        shapeLayer.lineWidth = 0.5
        shapeLayer.lineJoin = .round
    }

    func makeUI() {}
    func drawPath(_ path: UIBezierPath) {
        shapeLayer.path = path.cgPath
    }

    func setArrowImage(_ image: UIImage) {
        arrowImageView.image = image
    }

    func setArrowColor(_ color: UIColor) {
        arrowImageView.yp.set(tintColor: color)
    }
}
